import axios from 'axios';

var iaxios = axios.create({
  baseURL: '/v1'
});

// 登出
export const userLogout = () => {
	console.log("userLogout")
	return iaxios.get('/user/logout')
}

// 登录
export const userLogin = params => {
	console.log("userLogin")
	var reqParams = new URLSearchParams();
	reqParams.append('name', params.name)
	reqParams.append('passwd', params.passwd)
	return iaxios.post('/user/login', reqParams).
	then(res => res.data)
}

// 搜索
export const getCommodity = params => {
	console.log("getCommodity")
	return iaxios.get('/commodity/search', {params: params}).
	then(res => res.data)
}

// 广告位列表
export const getPositions = () => {
	console.log("getPositions")
	return iaxios.get('/position/list').
	then(res => res.data)
}

// 添加广告位
export const addPosition = params => {
	console.log("addPosition")
	return iaxios.post('/position/add', params).
	then(res => res.data)
}

// 更新广告位
export const editPosition = params => {
	console.log("editPosition")
	return iaxios.post('/position/update', params).
	then(res => res.data)
}

// 删除广告位
export const delPosition = params => {
	console.log("delPosition")
	return iaxios.get('/position/del', {params: params}).
	then(res => res.data)
}

// 批量删除广告位
export const batchDelPosition = params => {
	console.log("delPosition")
	return iaxios.get('/position/del', {params: params}).
	then(res => res.data)
}

// 推广模板
export const savePromoteTpl = params => {
	console.log("savePromoteTpl")
	return iaxios.post('/promotetpl/save', params).
	then(res => res.data)
}

export const getPromoteTpl = params => {
	console.log("getPromoteTpl")
	return iaxios.get('/promotetpl/get').
	then(res => res.data)
}
